home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / Crystal / 3rdparty / JavaVM / Plug-in / jplugin.exe / rt.jar / sun / awt / im / InputContext.class (.txt) next >
Encoding:
Java Class File  |  1998-04-16  |  2.0 KB  |  105 lines

  1. package sun.awt.im;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Component;
  5. import java.awt.Toolkit;
  6. import java.util.EventObject;
  7. import sun.awt.SunToolkit;
  8.  
  9. public class InputContext {
  10.    private InputMethod inputMethod;
  11.    private boolean inputMethodCreationFailed;
  12.    private Component currentClientComponent;
  13.  
  14.    protected InputContext() {
  15.    }
  16.  
  17.    public static InputContext getInstance() {
  18.       return new InputMethodContext();
  19.    }
  20.  
  21.    public synchronized void dispatchEvent(AWTEvent var1) {
  22.       InputMethod var2 = this.getInputMethod();
  23.       int var3 = var1.getID();
  24.       switch (var3) {
  25.          case 103:
  26.             this.dispose();
  27.             this.currentClientComponent = null;
  28.             return;
  29.          case 1004:
  30.             this.activate((Component)((EventObject)var1).getSource());
  31.             if (var2 != null) {
  32.                var2.dispatchEvent(var1);
  33.                return;
  34.             }
  35.             break;
  36.          case 1005:
  37.             if (var2 != null) {
  38.                var2.dispatchEvent(var1);
  39.             }
  40.  
  41.             this.deactivate((Component)((EventObject)var1).getSource());
  42.             return;
  43.          default:
  44.             if (var2 != null) {
  45.                var2.dispatchEvent(var1);
  46.             }
  47.       }
  48.  
  49.    }
  50.  
  51.    synchronized void activate(Component var1) {
  52.       this.currentClientComponent = var1;
  53.       if (this.inputMethod != null) {
  54.          if (this.inputMethod instanceof InputMethodAdapter) {
  55.             ((InputMethodAdapter)this.inputMethod).setClientComponent(var1);
  56.          }
  57.  
  58.          this.inputMethod.activate();
  59.       }
  60.  
  61.    }
  62.  
  63.    synchronized void deactivate(Component var1) {
  64.       if (this.inputMethod != null) {
  65.          this.inputMethod.deactivate();
  66.       }
  67.  
  68.       this.currentClientComponent = null;
  69.    }
  70.  
  71.    Component getClientComponent() {
  72.       Component var1 = this.currentClientComponent;
  73.       return var1;
  74.    }
  75.  
  76.    public void dispose() {
  77.       if (this.inputMethod != null) {
  78.          this.inputMethod.dispose();
  79.          this.inputMethod = null;
  80.       }
  81.  
  82.    }
  83.  
  84.    InputMethod getInputMethod() {
  85.       if (this.inputMethod != null) {
  86.          return this.inputMethod;
  87.       } else if (this.inputMethodCreationFailed) {
  88.          return null;
  89.       } else {
  90.          try {
  91.             Toolkit var1 = Toolkit.getDefaultToolkit();
  92.             this.inputMethod = ((SunToolkit)var1).getInputMethodAdapter();
  93.          } catch (Exception var2) {
  94.             this.inputMethodCreationFailed = true;
  95.          }
  96.  
  97.          if (this.inputMethod != null) {
  98.             this.inputMethod.setInputContext((InputMethodContext)this);
  99.          }
  100.  
  101.          return this.inputMethod;
  102.       }
  103.    }
  104. }
  105.